import { createSlice } from '@reduxjs/toolkit'

interface EnergyState {
  consumption: any[]
  statistics: any
  loading: boolean
  error: string | null
}

const initialState: EnergyState = {
  consumption: [],
  statistics: {},
  loading: false,
  error: null,
}

const energySlice = createSlice({
  name: 'energy',
  initialState,
  reducers: {
    setConsumption: (state, action) => {
      state.consumption = action.payload
    },
    setStatistics: (state, action) => {
      state.statistics = action.payload
    },
    updateConsumption: (state, action) => {
      state.consumption.push(action.payload)
    },
  },
})

export const { setConsumption, setStatistics, updateConsumption } = energySlice.actions
export default energySlice.reducer

